import headerHtmlRaw from "../../partials/header/header.html?raw";
import footerHtmlRaw from "../../partials/footer/footer.html?raw";

function extractBodyInnerHtml(html: string): string {
  const parser = new DOMParser();
  const doc = parser.parseFromString(html, "text/html");
  // 移除内嵌脚本，避免路径/重复执行问题
  doc.querySelectorAll("script").forEach((s) => s.remove());
  return doc.body ? doc.body.innerHTML : html;
}

// 注入页眉与页脚
const headerMount = document.getElementById("app-header");
const footerMount = document.getElementById("app-footer");
if (headerMount) headerMount.innerHTML = extractBodyInnerHtml(headerHtmlRaw);
if (footerMount) footerMount.innerHTML = extractBodyInnerHtml(footerHtmlRaw);

// 激活页眉/页脚对应的脚本与样式
import("../../partials/header/header.ts");
import("../../partials/footer/footer.ts");
